package com.zzyl.nursing.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.constant.HttpStatus;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.PageDto;
import com.zzyl.nursing.mapper.NursingProjectMapper;
import com.zzyl.nursing.mapper.NursingProjectMemberMapper;
import com.zzyl.nursing.service.NursingProjectMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@Service
public class NursingProjectMemberServiceImpl extends ServiceImpl<NursingProjectMemberMapper, NursingProject> implements NursingProjectMemberService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public TableDataInfo<NursingProject> syncProductList(PageDto nursingProjectMemberPageDto) {
        Page<NursingProject> page=new Page<>(nursingProjectMemberPageDto.getPageNum(), nursingProjectMemberPageDto.getPageSize());
        LambdaQueryWrapper<NursingProject> wrapper = Wrappers.<NursingProject>lambdaQuery()
                .eq(ObjectUtil.isNotEmpty(nursingProjectMemberPageDto.getStatus()),NursingProject::getStatus, nursingProjectMemberPageDto.getStatus())
                .like(StringUtils.isNotEmpty(nursingProjectMemberPageDto.getName()), NursingProject::getName, nursingProjectMemberPageDto.getName());
        page= page(page, wrapper);
        return getTableDataInfo(page);
    }

    private TableDataInfo<NursingProject> getTableDataInfo(Page<NursingProject> page) {
        TableDataInfo<NursingProject> tableDataInfo = new TableDataInfo<>();
        tableDataInfo.setTotal(page.getTotal());
        tableDataInfo.setRows(page.getRecords());
        tableDataInfo.setCode(HttpStatus.SUCCESS);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }

    @Override
    public NursingProject getNursingProjectById(Integer id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        return nursingProject;
    }
}
